package com.meiya.hugegraph.example;

import org.apache.hugegraph.driver.HugeClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.meiya.hugegraph.util.HugeGraphUtil;

/**
 * HugeGraphUtil工具类使用示例
 */
public class HugeGraphUtilDemo {

    private static final Logger logger = LoggerFactory.getLogger(HugeGraphUtilDemo.class);

    // HugeGraph服务器地址和图名称
    private static final String SERVER_URL = "http://localhost:8080";
    private static final String GRAPH_NAME = "hugegraph";

    public static void main(String[] args) {
        HugeClient client = null;

        try {
            // 1. 创建HugeClient
            client = HugeGraphUtil.createClient(SERVER_URL, GRAPH_NAME);
            logger.info("HugeClient创建成功");

            // 清除所有数据和schema
            // HugeGraphUtil.clearAll(client);

            // 或者单独清除图数据
            HugeGraphUtil.clearGraphData(client);

            // 或者单独清除schema
            // HugeGraphUtil.clearSchema(client);

        } catch (Exception e) {
            logger.error("操作HugeGraph时发生错误", e);
        } finally {
            // 4. 安全关闭client
            HugeGraphUtil.closeClient(client);
        }
    }

}